package com.teach.flavour.enums;

import com.common.utils.IBaseEnum;

import java.util.Arrays;
import java.util.Optional;

/**
 * @author hzz
 */

public enum SaltRank implements IBaseEnum {
    QINGDAN(1, "清淡"),
    NOMAL(2, "正常"),
    PIANXIAN(3, "偏咸"),
    KEPA(4, "重口");

    private Integer value;
    private String text;

    SaltRank(int value, String text) {
        this.value = value;
        this.text = text;
    }
    public synchronized static SaltRank fromCode(Integer code) {
        if (null != code) {
            Optional<SaltRank> optional = Arrays.asList(SaltRank.values()).stream().filter(x -> x.getValue() - code == 0).findAny();
            return optional.isPresent() ? optional.get() : null;
        }

        return null;
    }
    public synchronized static SaltRank textOf(String text) {
        if (null != text) {
            Optional<SaltRank> optional = Arrays.asList(SaltRank.values()).stream().filter(x -> x.getText().equals(text)).findAny();
            return optional.isPresent() ? optional.get() : null;
        }

        return null;
    }
    @Override
    public int getValue() {
        return this.value;
    }

    @Override
    public String getText() {
        return this.text;
    }

    @Override
    public String paraString() {
        return this.paraString();
    }
}
